﻿using Lsk.Data;
using Lsk.Business.DTO;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.Entity.Core.Objects;

namespace Lsk.Business
{
    public class PropertySearch
    {
        private lskEntities _entity;

        public PropertySearch()
        {
            _entity = new lskEntities();
        }


        public IEnumerable<GetSaleProperty_Result> GetSaleProperty(PropertySearchParameter search)
        {
            if (search.priceMax == null)
                search.priceMax = 0;
            if (search.priceMin == null)
                search.priceMin = 0;
            if (search.project == null)
                search.project = "";
            if (search.floorSize == null)
                search.floorSize = 0;
            if (search.landSize == null)
                search.landSize = 0;
            if (search.location == null)
                search.location = "";
            if (search.bestBuy == null)
                search.bestBuy = 2;
            if (search.offSet == null)
                search.offSet = 0;
            if (search.next == null)
                search.next = 500;  // determine how many property we return.
            if (search.floorSizeMin == null)
                search.floorSizeMin = 0;
            if (search.landSizeMin == null)
                search.landSizeMin = 0;
            if (search.StateId == null)
                search.StateId = "";

            // ObjectResult<GetSaleProperty_Result> result = _entity.GetSaleProperty(search.saleType, search.priceMax, search.priceMin, search.project, search.floorSize, search.landSize, search.location, search.bestBuy, search.offSet, search.next, search.floorSizeMin, search.landSizeMin);
            //ObjectResult<GetSaleProperty_Result> result = _entity.GetSaleProperty(search.saleType, search.priceMax, search.priceMin, search.project,search.floorSize,search.landSize, search.location, search.bestBuy,search.offSet,search.next, search.floorSizeMin,search.landSizeMin);
            ObjectResult<GetSaleProperty_Result> result = _entity.GetSaleProperty(search.saleType, search.priceMax, search.priceMin, search.project, search.floorSize, search.landSize, search.location, search.bestBuy, search.offSet, search.next, search.floorSizeMin, search.landSizeMin, search.StateId);
            
            return result.AsEnumerable<GetSaleProperty_Result>();
        }

        public IEnumerable<GetRentProperty_Result> GetRentProperty(PropertySearchParameter search)
        {
            if (search.priceMax == null)
                search.priceMax = 0;
            if (search.priceMin == null)
                search.priceMin = 0;
            if (search.project == null)
                search.project = "";
            if (search.floorSize == null)
                search.floorSize = 0;
            if (search.landSize == null)
                search.landSize = 0;
            if (search.location == null)
                search.location = "";
            if (search.bestBuy == null)
                search.bestBuy = 2;
            if (search.offSet == null)
                search.offSet = 0;
            if (search.next == null)
                search.next = 500;// determine how many property we return.
            if (search.floorSizeMin == null)
                search.floorSizeMin = 0;
            if (search.landSizeMin == null)
                search.landSizeMin = 0;
            if (search.StateId == null)
                search.StateId = "";

            // ObjectResult<GetSaleProperty_Result> result = _entity.GetSaleProperty(search.saleType, search.priceMax, search.priceMin, search.project, search.floorSize, search.landSize, search.location, search.bestBuy, search.offSet, search.next, search.floorSizeMin, search.landSizeMin);
            //ObjectResult<GetSaleProperty_Result> result = _entity.GetSaleProperty(search.saleType, search.priceMax, search.priceMin, search.project,search.floorSize,search.landSize, search.location, search.bestBuy,search.offSet,search.next, search.floorSizeMin,search.landSizeMin);


            ObjectResult<GetRentProperty_Result> result = _entity.GetRentProperty(search.saleType, 
                search.priceMax, search.priceMin, search.project, 
                search.floorSize, search.landSize, search.location, 
                search.offSet, search.next, 
                search.floorSizeMin, search.landSizeMin, search.StateId);

            return result.AsEnumerable<GetRentProperty_Result>();
        }
        
        public IEnumerable<GetBestBuyAllSaleProperty_Result> GetBestBuyProperty()
        {

            ObjectResult<GetBestBuyAllSaleProperty_Result> result = _entity.GetBestBuyAllSaleProperty(0);

            return result.AsEnumerable<GetBestBuyAllSaleProperty_Result>();
        }

        public IEnumerable<GetSalePropertyByAgent_Result> GetSalePropertiesByAgent(string agentName)
        {
            ObjectResult<GetSalePropertyByAgent_Result> result = _entity.GetSalePropertyByAgent(agentName);
            return result.AsEnumerable<GetSalePropertyByAgent_Result>();
        }

        public IEnumerable<GetRentPropertyByAgent_Result> GetRentPropertiesByAgent(string agentName)
        {
            ObjectResult<GetRentPropertyByAgent_Result> result = _entity.GetRentPropertyByAgent(agentName);
            return result.AsEnumerable<GetRentPropertyByAgent_Result>();
        }

        public IEnumerable<GetAllNewRentProperty_Result> GetAllNewRentProperty()
        {
            ObjectResult<GetAllNewRentProperty_Result> result = _entity.GetAllNewRentProperty();

            return result.AsEnumerable<GetAllNewRentProperty_Result>();
        }
        public IEnumerable<GetAllNewSaleProperty_Result> GetAllNewSaleProperty()
        {
            ObjectResult<GetAllNewSaleProperty_Result> result = _entity.GetAllNewSaleProperty(0);

            return result.AsEnumerable<GetAllNewSaleProperty_Result>();
        }
    }
}
